
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml" lang="zh_CN">
  <head>
    <meta charset="utf-8" />
    <title>fractions --- 分数 &#8212; Python 3.7.8 文档</title>
    <link rel="stylesheet" href="../_static/pydoctheme.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <script type="text/javascript" src="../_static/language_data.js"></script>
    <script type="text/javascript" src="../_static/translations.js"></script>
    
    <script type="text/javascript" src="../_static/sidebar.js"></script>
    
    <link rel="search" type="application/opensearchdescription+xml"
          title="在 Python 3.7.8 文档 中搜索"
          href="../_static/opensearch.xml"/>
    <link rel="author" title="关于这些文档" href="../about.html" />
    <link rel="index" title="索引" href="../genindex.html" />
    <link rel="search" title="搜索" href="../search.html" />
    <link rel="copyright" title="版权所有" href="../copyright.html" />
    <link rel="next" title="random --- 生成伪随机数" href="random.html" />
    <link rel="prev" title="decimal --- 十进制定点和浮点运算" href="decimal.html" />
    <link rel="shortcut icon" type="image/png" href="../_static/py.png" />
    <link rel="canonical" href="https://docs.python.org/3/library/fractions.html" />
    
    <script type="text/javascript" src="../_static/copybutton.js"></script>
    
    
    
    
    <style>
      @media only screen {
        table.full-width-table {
            width: 100%;
        }
      }
    </style>
 

  </head><body>
  
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>导航</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="总目录"
             accesskey="I">索引</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python 模块索引"
             >模块</a> |</li>
        <li class="right" >
          <a href="random.html" title="random --- 生成伪随机数"
             accesskey="N">下一页</a> |</li>
        <li class="right" >
          <a href="decimal.html" title="decimal --- 十进制定点和浮点运算"
             accesskey="P">上一页</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="https://www.python.org/">Python</a> &#187;</li>
        <li>
          <a href="../index.html">3.7.8 Documentation</a> &#187;
        </li>

          <li class="nav-item nav-item-1"><a href="index.html" >Python 标准库</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="numeric.html" accesskey="U">数字和数学模块</a> &#187;</li>
    <li class="right">
        

    <div class="inline-search" style="display: none" role="search">
        <form class="inline-search" action="../search.html" method="get">
          <input placeholder="快速搜索" type="text" name="q" />
          <input type="submit" value="转向" />
          <input type="hidden" name="check_keywords" value="yes" />
          <input type="hidden" name="area" value="default" />
        </form>
    </div>
    <script type="text/javascript">$('.inline-search').show(0);</script>
         |
    </li>

      </ul>
    </div>    

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <div class="section" id="module-fractions">
<span id="fractions-rational-numbers"></span><h1><a class="reference internal" href="#module-fractions" title="fractions: Rational numbers."><code class="xref py py-mod docutils literal notranslate"><span class="pre">fractions</span></code></a> --- 分数<a class="headerlink" href="#module-fractions" title="永久链接至标题">¶</a></h1>
<p><strong>源代码</strong> <a class="reference external" href="https://github.com/python/cpython/tree/3.7/Lib/fractions.py">Lib/fractions.py</a></p>
<hr class="docutils" />
<p><a class="reference internal" href="#module-fractions" title="fractions: Rational numbers."><code class="xref py py-mod docutils literal notranslate"><span class="pre">fractions</span></code></a> 模块支持分数运算。</p>
<p>分数实例可以由一对整数，一个分数，或者一个字符串构建而成。</p>
<dl class="class">
<dt id="fractions.Fraction">
<em class="property">class </em><code class="sig-prename descclassname">fractions.</code><code class="sig-name descname">Fraction</code><span class="sig-paren">(</span><em class="sig-param">numerator=0</em>, <em class="sig-param">denominator=1</em><span class="sig-paren">)</span><a class="headerlink" href="#fractions.Fraction" title="永久链接至目标">¶</a></dt>
<dt>
<em class="property">class </em><code class="sig-prename descclassname">fractions.</code><code class="sig-name descname">Fraction</code><span class="sig-paren">(</span><em class="sig-param">other_fraction</em><span class="sig-paren">)</span></dt>
<dt>
<em class="property">class </em><code class="sig-prename descclassname">fractions.</code><code class="sig-name descname">Fraction</code><span class="sig-paren">(</span><em class="sig-param">float</em><span class="sig-paren">)</span></dt>
<dt>
<em class="property">class </em><code class="sig-prename descclassname">fractions.</code><code class="sig-name descname">Fraction</code><span class="sig-paren">(</span><em class="sig-param">decimal</em><span class="sig-paren">)</span></dt>
<dt>
<em class="property">class </em><code class="sig-prename descclassname">fractions.</code><code class="sig-name descname">Fraction</code><span class="sig-paren">(</span><em class="sig-param">string</em><span class="sig-paren">)</span></dt>
<dd><p>第一个版本要求 <em>numerator</em> 和 <em>denominator</em> 是 <a class="reference internal" href="numbers.html#numbers.Rational" title="numbers.Rational"><code class="xref py py-class docutils literal notranslate"><span class="pre">numbers.Rational</span></code></a> 的实例，并返回一个新的 <a class="reference internal" href="#fractions.Fraction" title="fractions.Fraction"><code class="xref py py-class docutils literal notranslate"><span class="pre">Fraction</span></code></a> 实例，其值为 <code class="docutils literal notranslate"><span class="pre">numerator/denominator</span></code>。 如果 <em>denominator</em> 为 <code class="xref py py-const docutils literal notranslate"><span class="pre">0</span></code> 将会引发 <a class="reference internal" href="exceptions.html#ZeroDivisionError" title="ZeroDivisionError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ZeroDivisionError</span></code></a>。 第二个版本要求 <em>other_fraction</em> 是 <a class="reference internal" href="numbers.html#numbers.Rational" title="numbers.Rational"><code class="xref py py-class docutils literal notranslate"><span class="pre">numbers.Rational</span></code></a> 的实例，并返回一个 <a class="reference internal" href="#fractions.Fraction" title="fractions.Fraction"><code class="xref py py-class docutils literal notranslate"><span class="pre">Fraction</span></code></a> 实例且与传入值相等。 下两个版本接受 <a class="reference internal" href="functions.html#float" title="float"><code class="xref py py-class docutils literal notranslate"><span class="pre">float</span></code></a> 或 <a class="reference internal" href="decimal.html#decimal.Decimal" title="decimal.Decimal"><code class="xref py py-class docutils literal notranslate"><span class="pre">decimal.Decimal</span></code></a> 的实例，并返回一个 <a class="reference internal" href="#fractions.Fraction" title="fractions.Fraction"><code class="xref py py-class docutils literal notranslate"><span class="pre">Fraction</span></code></a> 实例且与传入值完全相等。 请注意由于二进制浮点数通常存在的问题 (参见 <a class="reference internal" href="../tutorial/floatingpoint.html#tut-fp-issues"><span class="std std-ref">浮点算术：争议和限制</span></a>)，<code class="docutils literal notranslate"><span class="pre">Fraction(1.1)</span></code> 的参数并不会精确等于 11/10，因此 <code class="docutils literal notranslate"><span class="pre">Fraction(1.1)</span></code> 也 <em>不会</em> 返回用户所期望的 <code class="docutils literal notranslate"><span class="pre">Fraction(11,</span> <span class="pre">10)</span></code>。 （请参阅下文中 <a class="reference internal" href="#fractions.Fraction.limit_denominator" title="fractions.Fraction.limit_denominator"><code class="xref py py-meth docutils literal notranslate"><span class="pre">limit_denominator()</span></code></a> 方法的文档。） 构造器的最后一个版本接受一个字符串或 unicode 实例。 此实例的通常形式为:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="p">[</span><span class="n">sign</span><span class="p">]</span> <span class="n">numerator</span> <span class="p">[</span><span class="s1">&#39;/&#39;</span> <span class="n">denominator</span><span class="p">]</span>
</pre></div>
</div>
<p>其中的可选项 <code class="docutils literal notranslate"><span class="pre">sign</span></code> 可以为 '+' 或 '-' 并且 <code class="docutils literal notranslate"><span class="pre">numerator</span></code> 和 <code class="docutils literal notranslate"><span class="pre">denominator</span></code> (如果存在) 是十进制数码的字符串。 此外，<a class="reference internal" href="functions.html#float" title="float"><code class="xref py py-class docutils literal notranslate"><span class="pre">float</span></code></a> 构造器所接受的任何表示一个有限值的字符串也都为 <a class="reference internal" href="#fractions.Fraction" title="fractions.Fraction"><code class="xref py py-class docutils literal notranslate"><span class="pre">Fraction</span></code></a> 构造器所接受。 不论哪种形式的输入字符串也都可以带有前缀和/或后缀的空格符。 这里是一些示例:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">fractions</span> <span class="kn">import</span> <span class="n">Fraction</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Fraction</span><span class="p">(</span><span class="mi">16</span><span class="p">,</span> <span class="o">-</span><span class="mi">10</span><span class="p">)</span>
<span class="go">Fraction(-8, 5)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Fraction</span><span class="p">(</span><span class="mi">123</span><span class="p">)</span>
<span class="go">Fraction(123, 1)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Fraction</span><span class="p">()</span>
<span class="go">Fraction(0, 1)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Fraction</span><span class="p">(</span><span class="s1">&#39;3/7&#39;</span><span class="p">)</span>
<span class="go">Fraction(3, 7)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Fraction</span><span class="p">(</span><span class="s1">&#39; -3/7 &#39;</span><span class="p">)</span>
<span class="go">Fraction(-3, 7)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Fraction</span><span class="p">(</span><span class="s1">&#39;1.414213 </span><span class="se">\t\n</span><span class="s1">&#39;</span><span class="p">)</span>
<span class="go">Fraction(1414213, 1000000)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Fraction</span><span class="p">(</span><span class="s1">&#39;-.125&#39;</span><span class="p">)</span>
<span class="go">Fraction(-1, 8)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Fraction</span><span class="p">(</span><span class="s1">&#39;7e-6&#39;</span><span class="p">)</span>
<span class="go">Fraction(7, 1000000)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Fraction</span><span class="p">(</span><span class="mf">2.25</span><span class="p">)</span>
<span class="go">Fraction(9, 4)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Fraction</span><span class="p">(</span><span class="mf">1.1</span><span class="p">)</span>
<span class="go">Fraction(2476979795053773, 2251799813685248)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">decimal</span> <span class="kn">import</span> <span class="n">Decimal</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Fraction</span><span class="p">(</span><span class="n">Decimal</span><span class="p">(</span><span class="s1">&#39;1.1&#39;</span><span class="p">))</span>
<span class="go">Fraction(11, 10)</span>
</pre></div>
</div>
<p><a class="reference internal" href="#fractions.Fraction" title="fractions.Fraction"><code class="xref py py-class docutils literal notranslate"><span class="pre">Fraction</span></code></a> 类继承自抽象基类 <a class="reference internal" href="numbers.html#numbers.Rational" title="numbers.Rational"><code class="xref py py-class docutils literal notranslate"><span class="pre">numbers.Rational</span></code></a>，并实现了该类的所有方法和操作。 <a class="reference internal" href="#fractions.Fraction" title="fractions.Fraction"><code class="xref py py-class docutils literal notranslate"><span class="pre">Fraction</span></code></a> 实例是可哈希的，并应当被视为不可变对象。 此外，<a class="reference internal" href="#fractions.Fraction" title="fractions.Fraction"><code class="xref py py-class docutils literal notranslate"><span class="pre">Fraction</span></code></a> 还具有以下属性和方法：</p>
<div class="versionchanged">
<p><span class="versionmodified changed">在 3.2 版更改: </span><a class="reference internal" href="#fractions.Fraction" title="fractions.Fraction"><code class="xref py py-class docutils literal notranslate"><span class="pre">Fraction</span></code></a> 构造器现在接受 <a class="reference internal" href="functions.html#float" title="float"><code class="xref py py-class docutils literal notranslate"><span class="pre">float</span></code></a> 和 <a class="reference internal" href="decimal.html#decimal.Decimal" title="decimal.Decimal"><code class="xref py py-class docutils literal notranslate"><span class="pre">decimal.Decimal</span></code></a> 实例。</p>
</div>
<dl class="attribute">
<dt id="fractions.Fraction.numerator">
<code class="sig-name descname">numerator</code><a class="headerlink" href="#fractions.Fraction.numerator" title="永久链接至目标">¶</a></dt>
<dd><p>最简分数形式的分子。</p>
</dd></dl>

<dl class="attribute">
<dt id="fractions.Fraction.denominator">
<code class="sig-name descname">denominator</code><a class="headerlink" href="#fractions.Fraction.denominator" title="永久链接至目标">¶</a></dt>
<dd><p>最简分数形式的分母。</p>
</dd></dl>

<dl class="method">
<dt id="fractions.Fraction.from_float">
<code class="sig-name descname">from_float</code><span class="sig-paren">(</span><em class="sig-param">flt</em><span class="sig-paren">)</span><a class="headerlink" href="#fractions.Fraction.from_float" title="永久链接至目标">¶</a></dt>
<dd><p>此类方法可构造一个 <a class="reference internal" href="#fractions.Fraction" title="fractions.Fraction"><code class="xref py py-class docutils literal notranslate"><span class="pre">Fraction</span></code></a> 来表示 <em>flt</em> 的精确值，该参数必须是一个 <a class="reference internal" href="functions.html#float" title="float"><code class="xref py py-class docutils literal notranslate"><span class="pre">float</span></code></a>。 请注意 <code class="docutils literal notranslate"><span class="pre">Fraction.from_float(0.3)</span></code> 的值并不等于 <code class="docutils literal notranslate"><span class="pre">Fraction(3,</span> <span class="pre">10)</span></code>。</p>
<div class="admonition note">
<p class="admonition-title">注解</p>
<p>从 Python 3.2 开始，在构造 <a class="reference internal" href="#fractions.Fraction" title="fractions.Fraction"><code class="xref py py-class docutils literal notranslate"><span class="pre">Fraction</span></code></a> 实例时可以直接使用 <a class="reference internal" href="functions.html#float" title="float"><code class="xref py py-class docutils literal notranslate"><span class="pre">float</span></code></a>。</p>
</div>
</dd></dl>

<dl class="method">
<dt id="fractions.Fraction.from_decimal">
<code class="sig-name descname">from_decimal</code><span class="sig-paren">(</span><em class="sig-param">dec</em><span class="sig-paren">)</span><a class="headerlink" href="#fractions.Fraction.from_decimal" title="永久链接至目标">¶</a></dt>
<dd><p>此类方法可构造一个 <a class="reference internal" href="#fractions.Fraction" title="fractions.Fraction"><code class="xref py py-class docutils literal notranslate"><span class="pre">Fraction</span></code></a> 来表示 <em>dec</em> 的精确值，该参数必须是一个 <a class="reference internal" href="decimal.html#decimal.Decimal" title="decimal.Decimal"><code class="xref py py-class docutils literal notranslate"><span class="pre">decimal.Decimal</span></code></a> 实例。</p>
<div class="admonition note">
<p class="admonition-title">注解</p>
<p>从 Python 3.2 开始，在构造 <a class="reference internal" href="#fractions.Fraction" title="fractions.Fraction"><code class="xref py py-class docutils literal notranslate"><span class="pre">Fraction</span></code></a> 实例时可以直接使用 <a class="reference internal" href="decimal.html#decimal.Decimal" title="decimal.Decimal"><code class="xref py py-class docutils literal notranslate"><span class="pre">decimal.Decimal</span></code></a> 实例。</p>
</div>
</dd></dl>

<dl class="method">
<dt id="fractions.Fraction.limit_denominator">
<code class="sig-name descname">limit_denominator</code><span class="sig-paren">(</span><em class="sig-param">max_denominator=1000000</em><span class="sig-paren">)</span><a class="headerlink" href="#fractions.Fraction.limit_denominator" title="永久链接至目标">¶</a></dt>
<dd><p>找到并返回一个 <a class="reference internal" href="#fractions.Fraction" title="fractions.Fraction"><code class="xref py py-class docutils literal notranslate"><span class="pre">Fraction</span></code></a> 使得其值最接近 <code class="docutils literal notranslate"><span class="pre">self</span></code> 并且分母不大于 max_denominator。 此方法适用于找出给定浮点数的有理数近似值：</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">fractions</span> <span class="kn">import</span> <span class="n">Fraction</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Fraction</span><span class="p">(</span><span class="s1">&#39;3.1415926535897932&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">limit_denominator</span><span class="p">(</span><span class="mi">1000</span><span class="p">)</span>
<span class="go">Fraction(355, 113)</span>
</pre></div>
</div>
<p>或是用来恢复被表示为一个浮点数的有理数：</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">math</span> <span class="kn">import</span> <span class="n">pi</span><span class="p">,</span> <span class="n">cos</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Fraction</span><span class="p">(</span><span class="n">cos</span><span class="p">(</span><span class="n">pi</span><span class="o">/</span><span class="mi">3</span><span class="p">))</span>
<span class="go">Fraction(4503599627370497, 9007199254740992)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Fraction</span><span class="p">(</span><span class="n">cos</span><span class="p">(</span><span class="n">pi</span><span class="o">/</span><span class="mi">3</span><span class="p">))</span><span class="o">.</span><span class="n">limit_denominator</span><span class="p">()</span>
<span class="go">Fraction(1, 2)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Fraction</span><span class="p">(</span><span class="mf">1.1</span><span class="p">)</span><span class="o">.</span><span class="n">limit_denominator</span><span class="p">()</span>
<span class="go">Fraction(11, 10)</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="fractions.Fraction.__floor__">
<code class="sig-name descname">__floor__</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#fractions.Fraction.__floor__" title="永久链接至目标">¶</a></dt>
<dd><p>返回最大的 <a class="reference internal" href="functions.html#int" title="int"><code class="xref py py-class docutils literal notranslate"><span class="pre">int</span></code></a> <code class="docutils literal notranslate"><span class="pre">&lt;=</span> <span class="pre">self</span></code>。 此方法也可通过 <a class="reference internal" href="math.html#math.floor" title="math.floor"><code class="xref py py-func docutils literal notranslate"><span class="pre">math.floor()</span></code></a> 函数来访问：</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">math</span> <span class="kn">import</span> <span class="n">floor</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">floor</span><span class="p">(</span><span class="n">Fraction</span><span class="p">(</span><span class="mi">355</span><span class="p">,</span> <span class="mi">113</span><span class="p">))</span>
<span class="go">3</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="fractions.Fraction.__ceil__">
<code class="sig-name descname">__ceil__</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#fractions.Fraction.__ceil__" title="永久链接至目标">¶</a></dt>
<dd><p>返回最小的 <a class="reference internal" href="functions.html#int" title="int"><code class="xref py py-class docutils literal notranslate"><span class="pre">int</span></code></a> <code class="docutils literal notranslate"><span class="pre">&gt;=</span> <span class="pre">self</span></code>。 此方法也可通过 <a class="reference internal" href="math.html#math.ceil" title="math.ceil"><code class="xref py py-func docutils literal notranslate"><span class="pre">math.ceil()</span></code></a> 函数来访问。</p>
</dd></dl>

<dl class="method">
<dt id="fractions.Fraction.__round__">
<code class="sig-name descname">__round__</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#fractions.Fraction.__round__" title="永久链接至目标">¶</a></dt>
<dt>
<code class="sig-name descname">__round__</code><span class="sig-paren">(</span><em class="sig-param">ndigits</em><span class="sig-paren">)</span></dt>
<dd><p>第一个版本返回一个 <a class="reference internal" href="functions.html#int" title="int"><code class="xref py py-class docutils literal notranslate"><span class="pre">int</span></code></a> 使得其值最接近 <code class="docutils literal notranslate"><span class="pre">self</span></code>，位值为二分之一时只对偶数舍入。第二个版本会将 <code class="docutils literal notranslate"><span class="pre">self</span></code> 舍入到最接近 <code class="docutils literal notranslate"><span class="pre">Fraction(1,</span> <span class="pre">10**ndigits)</span></code> 的倍数（如果 <code class="docutils literal notranslate"><span class="pre">ndigits</span></code> 为负值则为逻辑运算），位值为二分之一时同样只对偶数舍入。 此方法也可通过 <a class="reference internal" href="functions.html#round" title="round"><code class="xref py py-func docutils literal notranslate"><span class="pre">round()</span></code></a> 函数来访问。</p>
</dd></dl>

</dd></dl>

<dl class="function">
<dt id="fractions.gcd">
<code class="sig-prename descclassname">fractions.</code><code class="sig-name descname">gcd</code><span class="sig-paren">(</span><em class="sig-param">a</em>, <em class="sig-param">b</em><span class="sig-paren">)</span><a class="headerlink" href="#fractions.gcd" title="永久链接至目标">¶</a></dt>
<dd><p>返回整数 <em>a</em> 和 <em>b</em> 的最大公约数。如果 <em>a</em> 或 <em>b</em> 之一非零，则 <code class="docutils literal notranslate"><span class="pre">gcd(a,</span> <span class="pre">b)</span></code> 的绝对值是能同时整除 <em>a</em> 和 <em>b</em> 的最大整数。若 <em>b</em> 非零，则 <code class="docutils literal notranslate"><span class="pre">gcd(a,b)</span></code> 与 <em>b</em> 同号；否则返回值与 <em>a</em> 同号。<code class="docutils literal notranslate"><span class="pre">gcd(0,</span> <span class="pre">0)</span></code> 返回 <code class="docutils literal notranslate"><span class="pre">0</span></code>。</p>
<div class="deprecated">
<p><span class="versionmodified deprecated">3.5 版后已移除: </span>由 <a class="reference internal" href="math.html#math.gcd" title="math.gcd"><code class="xref py py-func docutils literal notranslate"><span class="pre">math.gcd()</span></code></a> 取代.</p>
</div>
</dd></dl>

<div class="admonition seealso">
<p class="admonition-title">参见</p>
<dl class="simple">
<dt><a class="reference internal" href="numbers.html#module-numbers" title="numbers: Numeric abstract base classes (Complex, Real, Integral, etc.)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">numbers</span></code></a> 模块</dt><dd><p>构成数字塔的所有抽象基类。</p>
</dd>
</dl>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <h4>上一个主题</h4>
  <p class="topless"><a href="decimal.html"
                        title="上一章"><code class="xref py py-mod docutils literal notranslate"><span class="pre">decimal</span></code> --- 十进制定点和浮点运算</a></p>
  <h4>下一个主题</h4>
  <p class="topless"><a href="random.html"
                        title="下一章"><code class="xref py py-mod docutils literal notranslate"><span class="pre">random</span></code> --- 生成伪随机数</a></p>
  <div role="note" aria-label="source link">
    <h3>本页</h3>
    <ul class="this-page-menu">
      <li><a href="../bugs.html">提交 Bug</a></li>
      <li>
        <a href="https://github.com/python/cpython/blob/3.7/Doc/library/fractions.rst"
            rel="nofollow">显示源代码
        </a>
      </li>
    </ul>
  </div>
        </div>
      </div>
      <div class="clearer"></div>
    </div>  
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>导航</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="总目录"
             >索引</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python 模块索引"
             >模块</a> |</li>
        <li class="right" >
          <a href="random.html" title="random --- 生成伪随机数"
             >下一页</a> |</li>
        <li class="right" >
          <a href="decimal.html" title="decimal --- 十进制定点和浮点运算"
             >上一页</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="https://www.python.org/">Python</a> &#187;</li>
        <li>
          <a href="../index.html">3.7.8 Documentation</a> &#187;
        </li>

          <li class="nav-item nav-item-1"><a href="index.html" >Python 标准库</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="numeric.html" >数字和数学模块</a> &#187;</li>
    <li class="right">
        

    <div class="inline-search" style="display: none" role="search">
        <form class="inline-search" action="../search.html" method="get">
          <input placeholder="快速搜索" type="text" name="q" />
          <input type="submit" value="转向" />
          <input type="hidden" name="check_keywords" value="yes" />
          <input type="hidden" name="area" value="default" />
        </form>
    </div>
    <script type="text/javascript">$('.inline-search').show(0);</script>
         |
    </li>

      </ul>
    </div>  
    <div class="footer">
    &copy; <a href="../copyright.html">版权所有</a> 2001-2020, Python Software Foundation.
    <br />
    Python 软件基金会是一个非盈利组织。
    <a href="https://www.python.org/psf/donations/">请捐助。</a>
    <br />
    最后更新于 6月 29, 2020.
    <a href="../bugs.html">发现了问题</a>？
    <br />
    使用<a href="http://sphinx.pocoo.org/">Sphinx</a>2.3.1 创建。
    </div>

  </body>
</html>